﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PNProject.EF;
using PNProject.Core;

namespace PNProject.Core.Converter
{
    public class FeedbackConverter
    {
        public static Feedback ToFeedback(FeedbackModel feed)
        {
            Feedback obj = new Feedback();
            try
            {
                obj.FeedbackID = Guid.Parse(feed.FeedbackID);
                obj.Name = feed.Name;
                obj.Address = feed.Address;
                obj.Phone = feed.Phone;
                obj.Email = feed.Email;
                obj.Title = feed.Title;
                obj.Message = feed.Message;
                obj.Lang = feed.Lang;
                obj.Country = feed.Country;
                obj.Province = feed.Province;
                return obj;
            }
            catch (Exception e)
            {
                return new Feedback();
            }
        }

        public static Feedback CopyFeedback(Feedback feed)
        {
            Feedback obj = new Feedback();
            try
            {
                obj.FeedbackID = feed.FeedbackID;
                obj.Name = feed.Name;
                obj.Phone = feed.Phone;
                obj.Email = feed.Email;
                obj.Address = feed.Address;
                obj.IsRead = feed.IsRead;
                obj.Message = feed.Message;
                obj.SentDate = feed.SentDate;
                obj.ReplyBy = feed.ReplyBy;
                obj.ReplyDate = feed.ReplyDate;
                obj.ReplyMessage = feed.ReplyMessage;
                obj.Type = feed.Type;
                obj.Title = feed.Title;
                obj.Lang = feed.Lang;
                obj.Country = feed.Country;
                obj.Province = feed.Province;
                return obj;
            }
            catch (Exception e)
            {
                return new Feedback();
            }
        }

        public static FeedbackModel FeedbackTo(Feedback feed)
        {
            FeedbackModel obj = new FeedbackModel();
            obj.FeedbackID = feed.FeedbackID.ToString();
            obj.Name = feed.Name;
            obj.Phone = feed.Phone;
            obj.Email = feed.Email;
            obj.Address = feed.Address;
            obj.IsRead = feed.IsRead.HasValue ? feed.IsRead.Value : false;
            obj.Message = feed.Message;
            obj.SentDate = feed.SentDate.HasValue ? PNLibraries.PNTimeFormat(feed.SentDate.Value,false, true) : "";
            obj.ReplyBy = feed.ReplyBy;
            obj.ReplyDate = feed.ReplyDate.HasValue ? feed.ReplyDate.Value.ToString() : "";
            obj.ReplyMessage = feed.ReplyMessage;
            obj.Type = feed.Type.HasValue ? feed.Type.Value : 0;
            obj.Title = feed.Title;
            obj.Lang = feed.Lang.HasValue ? feed.Lang.Value : true;
            obj.Country = feed.Country;
            obj.Province = feed.Province;
            return obj;
        }
    }
}